package players;

import weapons.SimpleArrow;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;

public class PlayerLeft {

    private String pl = "PlayerLeft.jpg";
    private int dx;
    private int dy;
    private int x;
    private int y;
    private int width = 22;
    private int height = 38;
    private int board_width = 480;
    private Image image;
    private ArrayList missiles;
    private final int BOWMAN_SIZE = 20;
    private int life = 4;
    
    public PlayerLeft() {
        ImageIcon ii = new ImageIcon(this.getClass().getResource(pl));
        image = ii.getImage().getScaledInstance(width, height, 1);
        missiles = new ArrayList();
        x = 0;
        y = 0;
    }

    public void move() {
        x += dx;
        y += dy;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Image getImage() {
        return image;
    }

    public ArrayList getMissiles() {
        return missiles;
    }

    public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        if (key == KeyEvent.VK_D) {
            fire();
        }
        /*
         if (key == KeyEvent.VK_LEFT) {
         dx = -1;
         }

         if (key == KeyEvent.VK_RIGHT) {
         dx = 1;
         }
         */
        if (key == KeyEvent.VK_W) {
            dy = -1;
        }

        if (key == KeyEvent.VK_S) {
            dy = 1;
        }
    }

    public void fire() {
        missiles.add(new SimpleArrow(x + BOWMAN_SIZE, y + BOWMAN_SIZE / 2, 0));
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();
        /*
         if (key == KeyEvent.VK_LEFT) {
         dx = 0;
         }

         if (key == KeyEvent.VK_RIGHT) {
         dx = 0;
         }
         */
        if (key == KeyEvent.VK_W) {
            dy = 0;
        }

        if (key == KeyEvent.VK_S) {
            dy = 0;
        }
    }

    public Rectangle getBounds() {
        return new Rectangle(x, y, width, height);
    }

    public void hit(String rocket) {
        life --;
    }

    public int getLife() {
        return life;
    }
   
    public void removeMissle(SimpleArrow m)
    {
        missiles.remove(m);
    }
    
}